<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增曲目')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-song-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">*曲目名称：</label>
                <div class="col-sm-8">
                    <input name="songName" class="form-control" type="text" placeholder="请输入曲目名称" required>
                    <input type="hidden" name="bookId" id="bookId" th:value="${bookId}"/>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">*作者：</label>
                <div class="col-sm-8">
                    <input name="author" class="form-control" type="text" placeholder="请输入曲目作者" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">*级别：</label>
                <div class="col-sm-8">
                    <select name="songLevel" id="songLevel" class="form-control m-b" th:with="type=${@dict.getType('sys_level')}" placeholder="请选择曲目级别" required>
                    	<option>请选择曲目级别：</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            
            <div class="form-group">
	            	<label class="col-sm-3 control-label">上传示范曲：</label>
		            <div class="col-sm-5">
	                    <input class="form-control" type="file" name="songfile" id="songfile" accept=".mp3">
	                    <input type="hidden" name="song" id="song">
	                </div>
	                <div class="col-sm-2">
	                    <button class="btn btn-success fileinput-button" type="button" id="btnsong">上传MP3音频文件</button>
	                </div>
	        </div>
            
            <div class="form-group">
	            	<label class="col-sm-3 control-label">上传乐谱：</label>
		            <div class="col-sm-5">
	                    <input class="form-control" type="file" name="musicfile" id="musicfile" accept=".xml">
	                    <input type="hidden" name="music" id="music">
	                </div>
	                <div class="col-sm-2">
	                    <button class="btn btn-success fileinput-button" type="button" id="btnmusic">上传XML格式乐谱</button>
	                </div>
	        </div>
	           
            <div class="form-group">
	            	<label class="col-sm-3 control-label">上传歌词：</label>
		            <div class="col-sm-5">
	                    <input class="form-control" type="file" name="lyricfile" id="lyricfile" accept=".lrc">
	                    <input type="hidden" name="lyric" id="lyric">
	                </div>
	                <div class="col-sm-2">
	                    <button class="btn btn-success fileinput-button" type="button" id="btnlyric">上传LRC歌词文件</button>
	                </div>
	           </div>
	           
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否启用：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_able_status')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:checked="${dict.default}">
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "system/song"
        $("#form-song-add").validate({
            focusCleanup: true
        });
        
        $('#btnsong').click(function() {
            var val = $("#songfile").val();
            if (val.length==0) {
                layer.alert("未选择MP3音频文件");
                return ;
            }
            var formdata = new FormData();
            formdata.append("file", document.getElementById("songfile").files[0]);
            $.ajax({
                url: ctx + "system/upload/pictrue",
                data: formdata,
                type: "post",
                processData: false,
                contentType: false,
                success: function(result) {
                	if(result != null && result != undefined){
                		layer.alert("上传成功");
                    	$("#song").val(result);//赋值
                	}
                }
            });
        });
        
        $('#btnmusic').click(function() {
        	var val = $("#musicfile").val();
            if (val.length==0) {
                layer.alert("未选择XML格式乐谱");
                return ;
            }
            var formdata = new FormData();
            formdata.append("file", document.getElementById("musicfile").files[0]);
            $.ajax({
                url: ctx + "system/upload/pictrue",
                data: formdata,
                type: "post",
                processData: false,
                contentType: false,
                success: function(result) {
                	if(result != null && result != undefined){
                		layer.alert("上传成功");
                    	$("#music").val(result);//赋值
                	}
                }
            });
        });
        
        $('#btnlyric').click(function() {
        	var val = $("#lyricfile").val();
            if (val.length==0) {
                layer.alert("未选择LRC歌词文件");
                return ;
            }
            var formdata = new FormData();
            formdata.append("file", document.getElementById("lyricfile").files[0]);
            $.ajax({
                url: ctx + "system/upload/pictrue",
                data: formdata,
                type: "post",
                processData: false,
                contentType: false,
                success: function(result) {
                	if(result != null && result != undefined){
                		layer.alert("上传成功");
                    	$("#lyric").val(result);//赋值
                	}
                }
            });
        });

        function submitHandler() {
            if ($.validate.form()) {
            	var formdata = new FormData();
                
                formdata.append("songName", $("input[name='songName']").val());
                formdata.append("bookId", $("input[name='bookId']").val());
                formdata.append("author", $("input[name='author']").val());
                
                formdata.append("song", $("input[name='song']").val());
                formdata.append("music", $("input[name='music']").val());
                formdata.append("lyric", $("input[name='lyric']").val());
                
                var options=$("#songLevel option:selected");
                formdata.append("songLevel", options.val());
                formdata.append("status", $("input[name='status']").val());
                
                $.ajax({
                    url: prefix + "/add",
                    data: formdata,
                    type: "post",
                    processData: false,
                    contentType: false,
                    success: function(result) {
                    	$.operate.saveSuccess(result);
                    }
                })
            }
        }
        
    </script>
</body>
</html>